﻿// 功能：简单的消息提示类
// 描述：模拟一下Android中的Toast，比原版Toast简单哟 O(∩_∩)O~
// 作者：温伟鹏
// 日期：2010/9/10 16:37:24

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace MeizuSDK.Presentation
{
    /// <summary>
    /// 简单的消息提示类
    /// </summary>
    public sealed class Toast
    {
        /// <summary>
        /// 比较短的持续显示时间
        /// </summary>
        public const uint ShortDuration = 1000;
        /// <summary>
        /// 普通的持续显示时间
        /// </summary>
        public const uint NormalDuration = 3000;
        /// <summary>
        /// 长的持续显示时间
        /// </summary>
        public const uint LongDuration = 5000;

        private static PopupDialog dialog;
        private static Label lblMsg;

        /// <summary>
        /// 构造Toast实例
        /// </summary>
        static Toast()
        {
        }

        /// <summary>
        /// 初始化控件
        /// </summary>
        private static void InitializeControls()
        {
            dialog = new PopupDialog();
            dialog.CloseMode = PopupDialogCloseMode.AutoClose;
            dialog.BgTransparent = true;

            lblMsg = new Label();
            lblMsg.AutoSize = true;
        }

        /// <summary>
        /// 显示通知
        /// </summary>
        /// <param name="message">通知消息</param>
        public static void Show(string message)
        {
            Show(message, NormalDuration);
        }
        /// <summary>
        /// 显示通知
        /// </summary>
        /// <param name="message">通知消息</param>
        /// <param name="duration">消息显示时间。单位：毫秒</param>
        public static void Show(string message, uint duration)
        {
            Show(null, message, duration);
        }
        /// <summary>
        /// 显示通知
        /// </summary>
        /// <param name="owner">通知所属的窗口</param>
        /// <param name="message">通知消息</param>
        /// <param name="duration">消息显示时间。单位：毫秒</param>
        public static void Show(IMzWindow owner, string message, uint duration)
        {
            InitializeControls();

            lblMsg.Text = message;
            lblMsg.ForeColor = Color.White;

            dialog.MainView = lblMsg;
            dialog.AutoCloseTimeOut = duration;

            dialog.ShowDialog(owner);
        }
    }
}
